package com.handinfo.uimenu.window;

import java.io.DataInputStream;
import java.io.IOException;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import com.handinfo.engine.AbstractGameScreen;
import com.handinfo.engine.GameManager;
import com.handinfo.game.ActorRole;
import com.handinfo.game.Task;
import com.handinfo.uimenu.AbsHyperLinker;
import com.handinfo.uimenu.UIAbstractWindow;
import com.handinfo.uimenu.UIDialogMenu;
import com.handinfo.uimenu.UIListener;
import com.handinfo.uimenu.UIManager;
import com.handinfo.uimenu.UIMessageBox;
import com.handinfo.uimenu.UIPalette;
import com.handinfo.uimenu.UIPopmenu;
import com.handinfo.uimenu.UITools;
import com.handinfo.uimenu.UIWindowFactory;
import com.handinfo.util.ArrayList;
import com.handinfo.util.Tools;
import com.test.touch.GameTouchManager;

public class UITaskWindow extends UIAbstractWindow
{
//	public static UITaskWindow s_instance = null;

	public UITaskWindow(int id)
	{
		super(id);
		initImage();
		m_state = STATUS_TASK_LIST;
		m_x = 0;
		m_y = 0;
		m_w = AbstractGameScreen.SCREEN_WIDTH;
		m_y = AbstractGameScreen.SCREEN_HEIGHT;
	}

	/**
	 * 2012-4-17 下午05:39:46
	 * venizeng
	 */
	public static void gotoTeach()
	{
		UITaskWindow taskwindow = (UITaskWindow) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_ID_TASK);
		taskwindow.m_state = taskwindow.STATUS_TASK_TEACH;
	}

	private void initImage()
	{
//		img_title_small = UIManager.getInstance().createImage(UIManager.RES_TITLE_SMALL);
//		img_title_middle = UIManager.getInstance().createImage(UIManager.RES_TITLE_MIDDLE);
//		img_select_corner = UIManager.getInstance().createImage(UIManager.RES_SELECT_CORNER);
		img_word_store = UIManager.getInstance().coinImage(UIManager.RES_WORD_STORE);
		img_word_action = UIManager.getInstance().coinImage(UIManager.RES_WORD_ACTION);
		img_word_active = UIManager.getInstance().coinImage(UIManager.RES_WORD_ACTIVE);
//		img_scroll_bar_arrows = UIManager.getInstance().createImage(UIManager.RES_SCROLL_BAR_ARROWS);
//		img_scroll_bar_ruling = UIManager.getInstance().createImage(UIManager.RES_SCROLL_BAR_RULING);
//		img_border_corner = UIManager.getInstance().createImage(UIManager.RES_BORDER_CORNER);
//		img_softkey = UIManager.getInstance().createImage(UIManager.RES_BUTTON_LEFT);
	}

	protected void paintContent(Graphics g)
	{
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
		UITools.drawAlphaBG(g);
		switch (m_state) {
			case STATUS_TASK_LIST:
				drawTaskList(g);
				break;
			case STATUS_TASK_NPC_DETAIL:
				drawTaskDetailNPC(g);
				break;
			case STATUS_TASK_ROLE_DETAIL:
				drawTaskDetailRole(g);
				break;
			case STATUS_TASK_HINT_PATHFINDING:
				drawTaskHintPathfinding(g);
				break;
			case STATUS_TASK_TEACH:
				drawTeach(g);
				break;
		}
	}

	private void drawTeach(Graphics g)
	{
		drawTaskList(g);
		int w = 100;
		String[] temps = null;
		if (m_order_teach == 0) {
			temps = Tools.getStrArray("走近切换到可接任务", w);
		}
		else {
			temps = Tools.getStrArray("这里显示您等级，可获取的任务", w);
		}
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
		g.setColor(0x8739821);
		UITools.paintYindaoDesxribe(g, ((AbstractGameScreen.SCREEN_WIDTH - w) >> 1),
				((AbstractGameScreen.SCREEN_HEIGHT) >> 1), w, temps);
	}

	private void drawTaskHintPathfinding(Graphics g)
	{
		// 绘制背景
		UITools.drawWindowSmallBackgroud(g);

		UITools.drawWindowSubcoat(g,
				UITools.X_SMALL_SUBCOAT,
				UITools.Y_SMALL_SUBCOAT,
				UITools.W_SMALL_SUBCOAT,
				UITools.H_SMALL_SUBCOAT,
				UIManager.getPaletteColor(UIPalette.COLOR_CBD_DEEP));

		if (m_hyperLinker != null) {
			g.setClip(UITools.X_SMALL_SUBCOAT, UITools.Y_SMALL_SUBCOAT,
					UITools.W_SMALL_SUBCOAT, UITools.H_SMALL_SUBCOAT);
			m_hyperLinker
					.paint(g, UITools.X_SMALL_SUBCOAT + UITools.GAP_LEFT, UITools.Y_SMALL_SUBCOAT + UITools.GAP_UP);

		}
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
		// 按5开始行走
//		UITools.drawColorString(g, WORD_PATHFINDING,
//				UITools.X_BG_SMALL + (UITools.W_BG_SMALL >> 1),
//				UITools.Y_BG_SMALL + UITools.H_BG_SMALL - 1,
//				UIManager.getPaletteColor(UIPalette.COLOR_WORD_NOS), Tools.HCENTER_BOTTOM);
		UITools.drawMiddleKey(g, UITools.X_BG_SMALL + (UITools.W_BG_SMALL >> 1),
				UITools.Y_BG_SMALL + UITools.H_BG_SMALL - 4, Tools.HCENTER_BOTTOM);
//		//绘制左右软键
//		UITools.drawSoftkey(g, UITools.BUTTON_INDEX_QUEDING, UITools.BUTTON_INDEX_FANHUI,
//				UITools.X_BG_SMALL,
//				UITools.Y_BG_SMALL,
//				UITools.W_BG_SMALL,
//				UITools.H_BG_SMALL);
		// 绘制左右软键
		UITools.drawWindowSoftkey(g, UITools.BUTTON_INDEX_CAOZUO, UITools.BUTTON_INDEX_FANHUI);

		// 绘制标题
//		UITools.drawTitle(g, "任务寻路提示",
//				UITools.X_BG_SMALL,
//				UITools.Y_BG_SMALL,
//				UITools.W_BG_SMALL,
//				UITools.H_TITLE);
		UITools.paintBackgroundTitleOn240320(g, UITools.X_BG_SMALL,
				UITools.Y_BG_SMALL,
				UITools.W_BG_SMALL,
				23, "任务寻路提示");
	}

	protected void keyLogic()
	{
		switch (m_state) {
			case STATUS_TASK_LIST:
				logicTaskList();
				break;
			case STATUS_TASK_ROLE_DETAIL:
				logicTaskDetailRole();
				break;
			case STATUS_TASK_NPC_DETAIL:
				logicTaskDetailNPC();
				break;
			case STATUS_TASK_HINT_PATHFINDING:
				logicTaskHintPathfinding();
				break;
			case STATUS_TASK_TEACH:
				logicTeach();
				break;
		}
	}

	private int m_order_teach;//新手引导-任务教学的时序

	private void logicTeach()
	{
		if (m_order_teach == 0) {
			if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_D)) {
				m_task_list_page = 0;
				m_task_list_index = 0;
				m_task_list_status = --m_task_list_status < 0 ? TASK_TYPE_ACCEPTABLY : m_task_list_status;
			}
			else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_B)) {
				m_task_list_page = 0;
				m_task_list_index = 0;
				m_task_list_status = ++m_task_list_status > TASK_TYPE_ACCEPTABLY ? 0 : m_task_list_status;
			}
			if (m_task_list_status == TASK_TYPE_ACCEPTABLY) {
				m_order_teach = 1;
			}
		}
		else {
			if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
				close();
			}
		}
	}

	private void logicTaskHintPathfinding()
	{
		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
				|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)
				|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY5)) {
			m_pathfinding_index = m_hyperLinker.actionOnFire();
			if (m_hyperLinker.getHyperLinkTypes()[m_pathfinding_index] == AbsHyperLinker.URL_NPC) {
				//TODO
				final UIPopmenu pop = (UIPopmenu) UIManager.getInstance().createWindow(
						UIWindowFactory.WINDOW_POPMENU);
				pop.setPopmenus(new String[] {
						"1.自动寻路", "2.直接传送" });
				pop.addListener(new UIListener() {

					public void actionPerformed()
					{
						if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
								|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)
								|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY5)) {
							int index = pop.getCurrentIndex();
							if (index == 0) {
								GameManager.getInstance().m_game_message.sendScenePathfinding(m_hyperLinker
										.getHyperLinkIds()[m_pathfinding_index]);
								UIManager.getInstance().removeWindow(pop);
							}
							else if (index == 1) {
								final UIMessageBox msg = (UIMessageBox) UIManager.getInstance().createWindow(
										UIWindowFactory.WINDOW_MESSAGEBOX);
								msg.setMessage("提示", "确定", "返回", "直接传送需要消耗神行符一枚，是否传送？");
								msg.addListener(new UIListener() {

									public void actionPerformed()
									{
										if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
												|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
											GameManager.getInstance().m_game_message.sendDelivery(m_hyperLinker
										    .getHyperLinkIds()[m_pathfinding_index]);
											UIManager.getInstance().removeWindow(msg);
										}
										else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
											UIManager.getInstance().removeWindow(msg);

										}

									}
								});

							}
							UIManager.getInstance().removeWindow(pop);
						}
						else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
							UIManager.getInstance().removeWindow(pop);
						}
						else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY1)) {
							GameManager.getInstance().m_game_message.sendScenePathfinding(m_hyperLinker
									.getHyperLinkIds()[m_pathfinding_index]);
							UIManager.getInstance().removeWindow(pop);
						}
						else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY2)) {
							final UIMessageBox msg = (UIMessageBox) UIManager.getInstance().createWindow(
									UIWindowFactory.WINDOW_MESSAGEBOX);
							msg.setMessage("提示", "确定", "返回", "直接传送需要消耗神行符一枚，是否传送？");
							msg.addListener(new UIListener() {

								public void actionPerformed()
								{
									if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
											|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
										GameManager.getInstance().m_game_message.sendDelivery(m_hyperLinker
											    .getHyperLinkIds()[m_pathfinding_index]);
										UIManager.getInstance().removeWindow(msg);
									}
									else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
										UIManager.getInstance().removeWindow(msg);

									}

								}
							});
							UIManager.getInstance().removeWindow(pop);
						}

					}
				});
//				GameManager.getInstance().m_game_message.sendScenePathfinding(m_hyperLinker
//						.getHyperLinkIds()[m_pathfinding_index]);
			}

		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
			UIManager.getInstance().removeWindow(this);
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)
				|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT)) {
			m_hyperLinker.actionOnUp();
//			if (m_hyperLinker != null && m_hyperLinker.getHyperLinkSize() > 0) {
//				m_pathfinding_index = --m_pathfinding_index < 0 ? m_hyperLinker.getHyperLinkSize() - 1 : m_pathfinding_index;
//			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_DOWN)
				|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT)) {
			m_hyperLinker.actionOnDown();
//			if (m_hyperLinker != null && m_hyperLinker.getHyperLinkSize() > 0) {
//				m_pathfinding_index = ++m_pathfinding_index >= m_hyperLinker.getHyperLinkSize() ? 0 : m_pathfinding_index;
//			}
		}
	}

	/******************* 界面绘制 *********************/
	/**
	 * 绘制个人任务列表
	 * @param g
	 */
	private void drawTaskList(Graphics g)
	{
		
		// 绘制背景
		UITools.drawWindowBackgroud(g);
		// 绘制内层窗体
		UITools.drawWindowSubcoat(g,
				UITools.X_SUBCOAT_HT,
				UITools.Y_SUBCOAT_HT,
				UITools.W_SUBCOAT_HT,
				UITools.H_SUBCOAT_HT);

		// 绘制状态标题
		drawTaskListTitle(g);
		// 绘制任务列表
		drawTaskListContent(g);
		// 绘制任务列表滚动条
		drawTaskListScrollBar(g);
		// 绘制左右软键
		UITools.drawWindowSoftkey(g, UITools.BUTTON_INDEX_CAOZUO, UITools.BUTTON_INDEX_FANHUI);
		// 绘制标题
		UITools.drawTitle(g, "任务列表");

	}

	/**
	 * 绘制个人任务详细信息
	 * @param g
	 */
	private void drawTaskDetailRole(Graphics g)
	{
		// 绘制背景
		UITools.drawWindowBackgroud(g);
		// 绘制上半部内层窗体,详细信息
		UITools.drawWindowSubcoat(g,
				UITools.X_32_SUBCOAT,
				UITools.Y_32_SUBCOAT,
				UITools.W_32_SUBCOAT,
				UITools.H_32_SUBCOAT,
				UIManager.getPaletteColor(UIPalette.COLOR_CBD_DEEP));
		if (m_task_view_page) {
			UITools.drawImageSelectBox(g, UITools.X_32_SUBCOAT,
					UITools.Y_32_SUBCOAT, UITools.W_32_SUBCOAT, UITools.H_32_SUBCOAT);
		}
		// 绘制奖励列表
//		m_task_role_view.paint(g,
//				UITools.X_32_SUBCOAT + UITools.GAP_LEFT,
//				UITools.Y_32_SUBCOAT + UITools.GAP_UP);
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
		if (m_role_view_array != null) {
			UITools.drawStringList(g, m_role_view_array,
					UITools.X_32_SUBCOAT + UITools.GAP_LEFT,
					UITools.Y_32_SUBCOAT + UITools.GAP_UP,
					m_task_role_view_index,
					UITools.AMOUNT_SUBCOAT_32_CONTENT,
					UIManager.getPaletteColor(UIPalette.COLOR_WORD_NOS));
			if (m_role_view_array.length > UITools.AMOUNT_SUBCOAT_32_CONTENT) {
				UITools.paintScrollBar(g,
						UITools.X_32_SUBCOAT + UITools.W_32_SUBCOAT,
						UITools.Y_32_SUBCOAT, UITools.H_32_SUBCOAT,
						m_task_role_view_index * 100 / (m_role_view_array.length - UITools.AMOUNT_SUBCOAT_32_CONTENT));
			}
		}

		// 绘制下半部内层窗体,详细信息
		UITools.drawWindowSubcoat(g,
				UITools.X_31_SUBCOAT,
				UITools.Y_31_SUBCOAT,
				UITools.W_31_SUBCOAT,
				UITools.H_31_SUBCOAT,
				UIManager.getPaletteColor(UIPalette.COLOR_CBD_DEEP));
		// 绘制任务详细信息

//		if (m_task_give_up) {//选择放弃任务
//			UITools.drawColorString(g, m_no_hyperLinker, 
//					UITools.X_31_SUBCOAT + UITools.GAP_LEFT,
//					UITools.Y_31_SUBCOAT + UITools.GAP_UP, Tools.WHITE, Tools.LEFT_TOP);
//			UITools.drawColorString(g, "放弃任务",
//					UITools.X_31_SUBCOAT + UITools.GAP_LEFT,
//					UITools.Y_31_SUBCOAT + UITools.GAP_UP + m_hyperLinker.getRealHeight(),
//					UIManager.getPaletteColor(UIPalette.COLOR_WORD_YESS), Tools.LEFT_TOP);
//			g.drawLine(UITools.X_31_SUBCOAT + UITools.GAP_LEFT,
//					UITools.Y_31_SUBCOAT + UITools.GAP_UP + m_hyperLinker.getRealHeight() + AbstractGameScreen.FONT_H - 2,
//					UITools.X_31_SUBCOAT + UITools.GAP_LEFT + AbstractGameScreen.s_font.stringWidth("放弃任务"),
//					UITools.Y_31_SUBCOAT + UITools.GAP_UP + m_hyperLinker.getRealHeight() + AbstractGameScreen.FONT_H - 2);
//		} else {
		if (m_hyperLinker != null) {
			m_hyperLinker.paint(g,
					UITools.X_31_SUBCOAT + UITools.GAP_LEFT,
					UITools.Y_31_SUBCOAT + UITools.GAP_UP);
			if (!m_task_view_page && !m_task_give_up) {
				g.setColor(0x4f3c4a);
				g.fillRect(UITools.X_31_SUBCOAT + UITools.GAP_LEFT, UITools.Y_31_SUBCOAT + UITools.GAP_UP
						+ m_hyperLinker.getRealHeight(),
						AbstractGameScreen.s_font.stringWidth("放弃任务"), AbstractGameScreen.FONT_H);
			}
			UITools.drawColorString(g, "放弃任务",
					UITools.X_31_SUBCOAT + UITools.GAP_LEFT,
					UITools.Y_31_SUBCOAT + UITools.GAP_UP + m_hyperLinker.getRealHeight(),
					UIManager.getPaletteColor(UIPalette.COLOR_WORD_NOS), Tools.LEFT_TOP);
		}
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
//		UITools.drawColorString(g, WORD_PATHFINDING,
//				UITools.X_BG + (UITools.W_BG >> 1),
//				UITools.Y_BG + UITools.H_BG - 2,
//				UIManager.getPaletteColor(UIPalette.COLOR_WORD_NOS), Tools.HCENTER_BOTTOM);
		UITools.drawMiddleKey(g, UITools.X_BG + (UITools.W_BG >> 1),
				UITools.Y_BG + UITools.H_BG - 3, Tools.HCENTER_BOTTOM);
//		}
		//绘制左右软键
		UITools.drawWindowSoftkey(g, UITools.BUTTON_INDEX_QUEDING, UITools.BUTTON_INDEX_FANHUI);
		// 绘制标题
		UITools.drawTitle(g, m_task_title);
	}

	/**
	 * 绘制NPC任务详细信息
	 * @param g
	 */
	private void drawTaskDetailNPC(Graphics g)
	{
		// 绘制背景
		UITools.drawWindowBackgroud(g);
		// 绘制上半部内层窗体,详细信息
		UITools.drawWindowSubcoat(g,
				UITools.X_32_SUBCOAT,
				UITools.Y_32_SUBCOAT,
				UITools.W_32_SUBCOAT,
				UITools.H_32_SUBCOAT,
				UIManager.getPaletteColor(UIPalette.COLOR_CBD_DEEP));
		// 绘制任务详细信息
		if (m_task_view_list != null) {
			UITools.drawStringList(g, m_task_view_list,
					UITools.X_32_SUBCOAT + UITools.GAP_LEFT,
					UITools.Y_32_SUBCOAT + (UITools.GAP_UP >> 1),
					m_task_detail_index, UITools.AMOUNT_SUBCOAT_32_CONTENT, UIManager
							.getPaletteColor(UIPalette.COLOR_WORD_NOS));
			if (m_task_view_list.length > UITools.AMOUNT_SUBCOAT_32_CONTENT) {
				UITools.drawScrollBar(g,
						UITools.X_32_SUBCOAT + UITools.W_32_SUBCOAT,
						UITools.Y_32_SUBCOAT,
						UITools.H_32_SUBCOAT,
						m_task_detail_index * 100 / (m_task_view_list.length - UITools.AMOUNT_SUBCOAT_32_CONTENT));
			}
		}
		// 绘制下半部内层窗体,详细信息
		UITools.drawWindowSubcoat(g,
				UITools.X_31_SUBCOAT,
				UITools.Y_31_SUBCOAT,
				UITools.W_31_SUBCOAT,
				UITools.H_31_SUBCOAT,
				UIManager.getPaletteColor(UIPalette.COLOR_CBD_DEEP));
		// 绘制奖励列表
		if (m_task_reward != null) {
			UITools.drawStringList(g, m_task_reward,
					UITools.X_31_SUBCOAT + UITools.GAP_LEFT,
					UITools.Y_31_SUBCOAT + (UITools.GAP_UP >> 1),
					0, m_task_reward.length, UIManager.getPaletteColor(UIPalette.COLOR_WORD_NOS));
		}

		//绘制滚动条
//		drawTaskDetailScrollBar(g);
		if (m_task_view != null) {
			if (m_task_view.m_status == TASK_STATUS_NORECEIVE) {
				UITools.drawWindowSoftkey(g, UITools.BUTTON_INDEX_JIESHOU, UITools.BUTTON_INDEX_FANHUI);
			}
			else if (m_task_view.m_status == TASK_STATUS_FINISH) {
				UITools.drawWindowSoftkey(g, UITools.BUTTON_INDEX_WANCHENG, UITools.BUTTON_INDEX_FANHUI);
			}
			else {
				//绘制左右软键
				UITools.drawWindowSoftkey(g, (byte) 0, UITools.BUTTON_INDEX_FANHUI);
			}
		}
		// 绘制标题
		UITools.drawTitle(g, m_task_view.m_name);
	}

//	/**
//	 * 绘制任务详细信息滚动条
//	 * @param g
//	 */
//	private void drawTaskDetailScrollBar(Graphics g) {
//		ArrayList list = getTaskListArray();
//		if (list != null) {
//			UITools.drawScrollBar(g,
//					img_scroll_bar_arrows,
//					img_scroll_bar_ruling,
//					UITools.COORD_X_COVER_SUBCOAT + UITools.WIDTH_COVER_SUBCOAT,
//					UITools.COORD_Y_COVER_SUBCOAT,
//					UITools.HEIGHT_COVER_SUBCOAT,
//					((m_task_detail_page + m_task_detail_index) * 100) / 100);
//		}
//		else {
//			UITools.drawScrollBar(g, img_scroll_bar_arrows, img_scroll_bar_ruling,
//					UITools.COORD_X_COVER_SUBCOAT + UITools.WIDTH_COVER_SUBCOAT,
//					UITools.COORD_Y_COVER_SUBCOAT,
//					UITools.HEIGHT_COVER_SUBCOAT,
//					-1);
//		}
//	}
	/**
	 * 绘制任务列表滚动条
	 * @param g
	 */
	private void drawTaskListScrollBar(Graphics g)
	{
		ArrayList list = getTaskListArray();
		if (list != null && list.size() > 1) {
			UITools.drawScrollBar(g,
					UITools.X_SCROLL_BAR,
					UITools.Y_SCROLL_BAR,
					UITools.H_SCROLL_BAR,
					((m_task_list_page + m_task_list_index) * 100) / (list.size() - 1));
		}
		else {
			UITools.drawScrollBar(g,
					UITools.X_SCROLL_BAR,
					UITools.Y_SCROLL_BAR,
					UITools.H_SCROLL_BAR,
					-1);
		}
	}

	/**
	 * 绘制任务列表标题
	 * 
	 * @param g
	 */
	private void drawTaskListTitle(Graphics g)
	{
		for (int i = 0, x = 0; i <= TASK_TYPE_ACCEPTABLY; i++) {
			x = UITools.X_BUTTON_3BIG + UITools.W_BUTTON_BIG * i;
			g.setClip(x, UITools.Y_BUTTON, UITools.W_BUTTON_BIG, UITools.H_BUTTON);
			if (i == m_task_list_status) {
//				g.drawImage(img_button_big[BUTTON_BIG_YES], x, UITools.Y_BUTTON, Tools.LEFT_TOP);
				UITools.paintLabel(g, x, UITools.Y_BUTTON, UITools.W_LABEL_BIG, UITools.H_LABEL, true);
				UITools.drawImageSelectBox(g, x, UITools.Y_BUTTON, UITools.W_BUTTON_BIG, UITools.H_BUTTON);
			}
			else {
//				g.drawImage(img_button_big[BUTTON_BIG_NO], x, UITools.Y_BUTTON, Tools.LEFT_TOP);
				UITools.paintLabel(g, x, UITools.Y_BUTTON, UITools.W_LABEL_BIG, UITools.H_LABEL, false);
			}
			switch (i) {
				case TASK_TYPE_DRAMA:
					g.drawImage(img_word_store, x + (UITools.W_BUTTON_BIG >> 1), UITools.Y_BUTTON
							+ (UITools.H_BUTTON >> 1), Tools.HCENTER_VCENTER);
					break;
				case TASK_TYPE_EVENT:
					g.drawImage(img_word_action, x + (UITools.W_BUTTON_BIG >> 1), UITools.Y_BUTTON
							+ (UITools.H_BUTTON >> 1), Tools.HCENTER_VCENTER);
					break;
				case TASK_TYPE_ACCEPTABLY:
					g.drawImage(img_word_active, x + (UITools.W_BUTTON_BIG >> 1), UITools.Y_BUTTON
							+ (UITools.H_BUTTON >> 1), Tools.HCENTER_VCENTER);
					break;
			}
		}
		//绘制左右*#
//		UITools.drawLabelArrows(g, UITools.X_BUTTON_3BIG, UITools.Y_BUTTON, UITools.W_BUTTON_BIG
//				* (TASK_TYPE_ACCEPTABLY + 1), true, true);
	}

	/**
	 * 绘制任务列表内容
	 * 
	 * @param g
	 */
	private void drawTaskListContent(Graphics g)
	{
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
		for (int i = 0; i < UITools.AMOUNT_SUBCOAT_HT_CONTENT; i++) {
			drawContentBox(g, UITools.X_SUBCOAT_HT, UITools.Y_SUBCOAT_HT,
					UITools.W_SUBCOAT_HT, UITools.H_SINGLE_BAR, i);
		}
		ArrayList list = getTaskListArray();
		if (list != null && list.size() > 0) {
			UITools.drawSelectBox(g, UITools.X_SUBCOAT_HT, UITools.Y_SUBCOAT_HT + m_task_list_index
					* UITools.H_SINGLE_BAR + 2,
					UITools.W_SUBCOAT_HT, AbstractGameScreen.FONT_H + UITools.GAP_EACH_LINE);
		}
	}

	/**
	 * 绘制内层单框
	 * @param g
	 * @param x
	 * @param y
	 * @param w
	 * @param h
	 * @param index
	 * 当前页面的索引
	 */
	private void drawContentBox(Graphics g, int x, int y, int w, int h, int index)
	{
		ArrayList list = getTaskListArray();
		if (list != null && list.size() > 0) {
			Task task = null;
			if (m_task_list_page + index < list.size()) {
				task = (Task) list.elementAt(m_task_list_page + index);
				g.setClip(x, y, w - 12, h + index * UITools.H_SINGLE_BAR);
				task.drawContent(g, x + 6, y + index * UITools.H_SINGLE_BAR
						+ ((UITools.H_SINGLE_BAR - AbstractGameScreen.s_font.getHeight()) >> 1) + 1);
			}
		}
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
	}

	/******************* 界面逻辑 *********************/
	/**
	 * 个人任务列表逻辑
	 */
	private ArrayList getTaskListArray()
	{
		switch (m_task_list_status) {
			case TASK_TYPE_DRAMA:
				return GameManager.getInstance().m_role.m_drama_list;
			case TASK_TYPE_EVENT:
				return GameManager.getInstance().m_role.m_event_list;
			case TASK_TYPE_ACCEPTABLY:
				return GameManager.getInstance().m_role.m_acceptably_list;
		}
		return null;
	}

	/**
	 * 任务列表
	 */
	private void logicTaskList()
	{
		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)) {
			int len = 0;
			switch (m_task_list_status) {
				case TASK_TYPE_DRAMA:
					len = GameManager.getInstance().m_role.m_drama_list.size();
					break;
				case TASK_TYPE_EVENT:
					len = GameManager.getInstance().m_role.m_event_list.size();
					break;
				case TASK_TYPE_ACCEPTABLY:
					len = GameManager.getInstance().m_role.m_acceptably_list.size();
					break;
			}
			byte[] result = UITools.keyPressedIndexPage(m_task_list_index, m_task_list_page,
					len, UITools.AMOUNT_SUBCOAT_HT_CONTENT, UITools.OPERATION_MINUS);
			m_task_list_index = result[UITools.KPIP_INDEX];
			m_task_list_page = result[UITools.KPIP_PAGE];
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_DOWN)) {
			int len = 0;
			switch (m_task_list_status) {
				case TASK_TYPE_DRAMA:
					len = GameManager.getInstance().m_role.m_drama_list.size();
					break;
				case TASK_TYPE_EVENT:
					len = GameManager.getInstance().m_role.m_event_list.size();
					break;
				case TASK_TYPE_ACCEPTABLY:
					len = GameManager.getInstance().m_role.m_acceptably_list.size();
					break;
			}
			byte[] result = UITools.keyPressedIndexPage(m_task_list_index, m_task_list_page,
					len, UITools.AMOUNT_SUBCOAT_HT_CONTENT, UITools.OPERATION_ADD);
			m_task_list_index = result[UITools.KPIP_INDEX];
			m_task_list_page = result[UITools.KPIP_PAGE];
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_D)) {
			m_task_list_page = 0;
			m_task_list_index = 0;
			m_task_list_status = --m_task_list_status < 0 ? TASK_TYPE_ACCEPTABLY : m_task_list_status;
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_B)) {
			m_task_list_page = 0;
			m_task_list_index = 0;
			m_task_list_status = ++m_task_list_status > TASK_TYPE_ACCEPTABLY ? 0 : m_task_list_status;
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
			m_task_list_page = 0;
			m_task_list_index = 0;
			UIManager.getInstance().removeWindow(this);
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
				|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
			m_task_operate_id = m_task_list_page + m_task_list_index;
			if (m_task_list_status == TASK_TYPE_DRAMA) {
				ArrayList dramaList = GameManager.getInstance().m_role.m_drama_list;
				if (dramaList.size() > m_task_operate_id) {
					Task task = (Task) dramaList.elementAt(m_task_operate_id);
					m_task_operate_type = TASK_TYPE_DRAMA;
					GameManager.getInstance().m_game_message.sendRoleTaskView(task.m_key);
				}
			}
			else if (m_task_list_status == TASK_TYPE_EVENT) {
				ArrayList eventList = GameManager.getInstance().m_role.m_event_list;
				if (eventList.size() > m_task_operate_id) {
					Task task = (Task) eventList.elementAt(m_task_operate_id);
					m_task_operate_type = TASK_TYPE_EVENT;
					GameManager.getInstance().m_game_message.sendRoleTaskView(task.m_key);
				}
			}
			else if (m_task_list_status == TASK_TYPE_ACCEPTABLY) {
				ArrayList acceptablyList = GameManager.getInstance().m_role.m_acceptably_list;
				if (acceptablyList.size() > m_task_operate_id) {
					final Task task = (Task) acceptablyList.elementAt(m_task_operate_id);
					if (task != null) {
						m_task_operate_type = TASK_TYPE_ACCEPTABLY;
//						final UIMessageBox mb = (UIMessageBox) UIManager.getInstance().createWindow(
//								UIWindowFactory.WINDOW_MESSAGEBOX);
//						mb.setMessage(task.m_name, "是否去领取此任务?");
//						mb.addListener(new UIListener() {
//							public void actionPerformed()
//							{
//								if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)
//										|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)) {
//									GameManager.getInstance().m_game_message.sendScenePathfinding(task.m_npc_key);
//									Tools.debugPrintln("可接任务寻路key : " + task.m_npc_key);
//									UIManager.getInstance().removeWindow(mb);
//								}
//								else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
//									UIManager.getInstance().removeWindow(mb);
//								}
//							}
//						});
						//TODO
						final UIPopmenu pop = (UIPopmenu) UIManager.getInstance().createWindow(
								UIWindowFactory.WINDOW_POPMENU);
						pop.setPopmenus(new String[] {
								"1.自动寻路", "2.直接传送" });
						pop.addListener(new UIListener() {
		
							public void actionPerformed()
							{
								if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
										|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)
										|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY5)) {
									int index = pop.getCurrentIndex();
									if (index == 0) {
										GameManager.getInstance().m_game_message.sendScenePathfinding(task.m_npc_key);
										UIManager.getInstance().removeWindow(pop);
									}
									else if (index == 1) {
										final UIMessageBox msg = (UIMessageBox) UIManager.getInstance().createWindow(
												UIWindowFactory.WINDOW_MESSAGEBOX);
										msg.setMessage("提示", "确定", "返回", "直接传送需要消耗神行符一枚，是否传送？");
										msg.addListener(new UIListener() {
		
											public void actionPerformed()
											{
												if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
														|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
													GameManager.getInstance().m_game_message.sendDelivery(task.m_npc_key);
													UIManager.getInstance().removeWindow(msg);
												}
												else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
													UIManager.getInstance().removeWindow(msg);
		
												}
		
											}
										});
		
									}
									UIManager.getInstance().removeWindow(pop);
								}
								else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
									UIManager.getInstance().removeWindow(pop);
								}
								else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY1)) {
									GameManager.getInstance().m_game_message.sendScenePathfinding(task.m_npc_key);
									UIManager.getInstance().removeWindow(pop);
								}
								else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY2)) {
									final UIMessageBox msg = (UIMessageBox) UIManager.getInstance().createWindow(
											UIWindowFactory.WINDOW_MESSAGEBOX);
									msg.setMessage("提示", "确定", "返回", "直接传送需要消耗神行符一枚，是否传送？");
									msg.addListener(new UIListener() {
		
										public void actionPerformed()
										{
											if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
													|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
												GameManager.getInstance().m_game_message.sendDelivery(task.m_npc_key);
												UIManager.getInstance().removeWindow(msg);
											}
											else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
												UIManager.getInstance().removeWindow(msg);
		
											}
		
										}
									});
									UIManager.getInstance().removeWindow(pop);
								}
		
							}
						});
					}
				}
			}
		}
		if (++m_timer > 1000000) {
			m_timer = 0;
		}
	}

	private int m_timer = 0;

	/**
	 * 玩家任务详细信息逻辑
	 */
	private void logicTaskDetailRole()
	{
		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)) {
			if (m_task_view_page) {
				if (m_role_view_array != null && m_role_view_array.length > UITools.AMOUNT_SUBCOAT_32_CONTENT) {
					if (m_task_role_view_index == 0) {
						m_task_give_up = false;
						m_task_view_page = false;
						m_hyperLinker.setIndex(-1);
					}
					else {
						m_task_role_view_index--;
					}
				}
				else {
					m_task_give_up = false;
					m_task_view_page = false;
					m_hyperLinker.setIndex(-1);
				}
			}
			else {
				if (m_task_give_up) {
					m_task_give_up = false;
					m_task_view_page = true;
					m_hyperLinker.setIndex(-1);
				}
				else {
					if (m_hyperLinker.getHyperLinkSize() > 0) {
						m_task_give_up = true;
						m_task_view_page = false;
						m_hyperLinker.setIndex(0);
					}
					else {
						if (m_role_view_array != null && m_role_view_array.length > UITools.AMOUNT_SUBCOAT_32_CONTENT) {
							m_task_give_up = false;
							m_task_view_page = true;
							m_hyperLinker.setIndex(-1);
						}
					}
				}
			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_DOWN)) {
			if (m_task_view_page) {
				if (m_role_view_array != null && m_role_view_array.length > UITools.AMOUNT_SUBCOAT_32_CONTENT) {
					if (m_task_role_view_index >= m_role_view_array.length - UITools.AMOUNT_SUBCOAT_32_CONTENT) {
						m_task_role_view_index = 0;
						if (m_hyperLinker.getHyperLinkSize() > 0) {
							m_task_give_up = true;
							m_task_view_page = false;
							m_hyperLinker.setIndex(0);
						}
						else {
							m_task_give_up = false;
							m_task_view_page = false;
							m_hyperLinker.setIndex(-1);
						}
					}
					else {
						m_task_role_view_index++;
					}
				}
				else {
					if (m_hyperLinker.getHyperLinkSize() > 0) {
						m_task_give_up = true;
						m_task_view_page = false;
						m_hyperLinker.setIndex(0);
					}
					else {
						m_task_give_up = false;
						m_task_view_page = false;
						m_hyperLinker.setIndex(-1);
					}
				}
			}
			else {
				if (m_task_give_up) {
					m_task_give_up = false;
					m_task_view_page = false;
					m_hyperLinker.setIndex(-1);
				}
				else {
					if (m_role_view_array != null && m_role_view_array.length > UITools.AMOUNT_SUBCOAT_32_CONTENT) {
						m_task_give_up = false;
						m_task_view_page = true;
						m_hyperLinker.setIndex(-1);
					}
				}
			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT)) {
			if (!m_task_view_page && m_task_give_up)
				m_hyperLinker.actionOnLeft();
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT)) {
			if (!m_task_view_page && m_task_give_up)
				m_hyperLinker.actionOnRight();
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
			setWindowStatus(STATUS_TASK_LIST);
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
				|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)
				|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY5)) {
//			GameManager.getInstance().m_game_message.sendScenePathfinding(m_hyperLinker.getHyperItemId()[0]);
			if (!m_task_view_page) {
				if (!m_task_give_up) {
					m_message_box = (UIMessageBox) UIManager.getInstance().createWindow(
							UIWindowFactory.WINDOW_MESSAGEBOX);
					m_message_box.setMessage("确认放弃此任务?");
					m_message_box.setCentre();
					m_message_box.addListener(new UIListener() {
						public void actionPerformed()
						{
							if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
									|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
								GameManager.getInstance().m_game_message.sendTaskAbort(m_task_view.m_key);
							}
							else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
								UIManager.getInstance().removeWindow(m_message_box);
							}
						}
					});
				}
				else {
					m_pathfinding_index = m_hyperLinker.actionOnFire();
					if (m_pathfinding_index > -1) {
						if (m_hyperLinker.getHyperLinkTypes()[m_pathfinding_index] == AbsHyperLinker.URL_NPC) {
							UIMenu menu = (UIMenu) UIManager.getInstance()
									.getWindowById(UIWindowFactory.WINDOW_MENU_LR);
							if (menu != null) {
								UIManager.getInstance().removeWindow(menu);
							}
							//TODO
							final UIPopmenu pop = (UIPopmenu) UIManager.getInstance().createWindow(
									UIWindowFactory.WINDOW_POPMENU);
							pop.setPopmenus(new String[] {
									"1.自动寻路", "2.直接传送" });
							pop.addListener(new UIListener() {
			
								public void actionPerformed()
								{
									if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
											|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)
											|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY5)) {
										int index = pop.getCurrentIndex();
										if (index == 0) {
											GameManager.getInstance().m_game_message.sendScenePathfinding(m_hyperLinker
													.getHyperLinkIds()[m_pathfinding_index]);
											UIManager.getInstance().removeWindow(pop);
										}
										else if (index == 1) {
											final UIMessageBox msg = (UIMessageBox) UIManager.getInstance().createWindow(
													UIWindowFactory.WINDOW_MESSAGEBOX);
											msg.setMessage("提示", "确定", "返回", "直接传送需要消耗神行符一枚，是否传送？");
											msg.addListener(new UIListener() {
			
												public void actionPerformed()
												{
													if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
															|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
														GameManager.getInstance().m_game_message.sendDelivery(m_hyperLinker
													    .getHyperLinkIds()[m_pathfinding_index]);
														UIManager.getInstance().removeWindow(msg);
													}
													else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
														UIManager.getInstance().removeWindow(msg);
			
													}
			
												}
											});
			
										}
										UIManager.getInstance().removeWindow(pop);
									}
									else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
										UIManager.getInstance().removeWindow(pop);
									}
									else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY1)) {
										GameManager.getInstance().m_game_message.sendScenePathfinding(m_hyperLinker
												.getHyperLinkIds()[m_pathfinding_index]);
										UIManager.getInstance().removeWindow(pop);
									}
									else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY2)) {
										final UIMessageBox msg = (UIMessageBox) UIManager.getInstance().createWindow(
												UIWindowFactory.WINDOW_MESSAGEBOX);
										msg.setMessage("提示", "确定", "返回", "直接传送需要消耗神行符一枚，是否传送？");
										msg.addListener(new UIListener() {
			
											public void actionPerformed()
											{
												if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
														|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
													GameManager.getInstance().m_game_message.sendDelivery(m_hyperLinker
														    .getHyperLinkIds()[m_pathfinding_index]);
													UIManager.getInstance().removeWindow(msg);
												}
												else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
													UIManager.getInstance().removeWindow(msg);
			
												}
			
											}
										});
										UIManager.getInstance().removeWindow(pop);
									}
			
								}
							});
						}
					}
				}
			}
		}
	}

	/**
	 * NPC任务详细信息逻辑
	 */
	private void logicTaskDetailNPC()
	{
		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)) {
			m_task_detail_index = --m_task_detail_index < 0 ? 0 : m_task_detail_index;
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_DOWN)) {
			m_task_detail_index = ++m_task_detail_index >
					(m_task_view_list.length - UITools.AMOUNT_SUBCOAT_32_CONTENT) ? (--m_task_detail_index)
							: m_task_detail_index;
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
			UIManager.getInstance().removeWindow(this);
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
				|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
			if (m_task_view.m_status == TASK_STATUS_NORECEIVE) {
				GameManager.getInstance().m_game_message.sendTaskBegin(m_task_view.m_key);
			}
			else if (m_task_view.m_status == TASK_STATUS_FINISH) {
				GameManager.getInstance().m_game_message.sendTaskFinish(m_task_view.m_key);
			}
		}
	}

	private void refreshRoleTaskViewData()
	{
		m_task_title = m_task_view.m_name;

		String text = AbsHyperLinker.removeHyper(m_task_view.m_depict) + AbsHyperLinker.TYPE_CONTENT_CHANGEROW;
		text += "奖励:" + AbsHyperLinker.TYPE_CONTENT_CHANGEROW;
		text += "经验:" + m_task_view.m_exp + AbsHyperLinker.TYPE_CONTENT_CHANGEROW;
		short[] money = ActorRole.getMoney(m_task_view.m_money);
		String moneytext = "";
		if (money[0] > 0) {
			moneytext += (money[0] + "金");
		}
		if (money[1] > 0) {
			moneytext += (money[1] + "银");
		}
		if (money[2] > 0) {
			moneytext += (money[2] + "铜");
		}
		text += "金钱:" + moneytext + AbsHyperLinker.TYPE_CONTENT_CHANGEROW;
		if (m_task_view.m_propID != null) {
			if (m_task_view.m_propID.length > 0) {
//				text += "道具:" + AbsHyperLinker.TYPE_CONTENT_CHANGEROW;
				for (byte i = 0; i < m_task_view.m_propID.length; i++) {
					text += m_task_view.m_propID[i] + "x" + m_task_view.m_propCount[i]
							//					        + (i == m_task_view.m_propID.length - 1 ? Integer.toString(AbsHyperLinker.TYPE_CONTENT_CHANGEROW) : ",");
							+ (i == m_task_view.m_propID.length - 1 ? AbsHyperLinker.TYPE_CONTENT_CHANGEROW : ",");
				}
			}
		}
		if (m_task_view.m_renownID != null) {
			if (m_task_view.m_renownID.length > 0) {
				text += "声望:" + AbsHyperLinker.TYPE_CONTENT_CHANGEROW;
				for (byte i = 0; i < m_task_view.m_renownID.length; i++) {
					text += m_task_view.m_renownID[i] + "x" + m_task_view.m_renownCount[i]
							+ (i == m_task_view.m_renownID.length - 1 ? AbsHyperLinker.TYPE_CONTENT_CHANGEROW : ",");
				}
			}
		}
		text += m_task_view.m_progress;
//		m_task_role_view = null;
//		m_task_role_view = AbsHyperLinker.createHyperLinker(text, UITools.W_32_SUBCOAT - (UITools.GAP_LEFT << 1), UITools.H_32_SUBCOAT - (UITools.GAP_UP << 1));
		m_role_view_array = Tools.splitString(text, AbstractGameScreen.s_font, '`', UITools.W_32_SUBCOAT
				- (UITools.GAP_LEFT << 1));

		m_hyperLinker = null;
		m_hyperLinker = AbsHyperLinker.createHyperLinker(m_task_view.m_pathfinding_tip,
				UITools.W_31_SUBCOAT - (UITools.GAP_LEFT << 1), UITools.H_31_SUBCOAT - (UITools.GAP_UP << 1));
//		m_no_hyperLinker = AbsHyperLinker.removeHyper(m_task_view.m_depict);
		m_pathfinding_index = 0;
		m_task_view_page = false;
		if (m_hyperLinker.getHyperLinkSize() > 0) {
			m_task_give_up = true;
		}
		else {
			m_task_give_up = false;
		}

	}

	private void refreshNPCTaskViewData()
	{
		m_task_title = m_task_view.m_name;
//		m_hyperLinker = null;
//		m_hyperLinker = AbsHyperLinker.createHyperLinker(m_task_view.m_depict,
//				UITools.WIDTH_32_SUBCOAT - (UITools.GAP_LEFT << 1), UITools.HEIGHT_32_SUBCOAT - (UITools.GAP_UP << 1));
		m_pathfinding_index = 0;
		String text = AbsHyperLinker.removeHyper(m_task_view.m_depict);
		m_task_view_list = Tools.splitString(text, AbstractGameScreen.s_font, '`', UITools.W_32_SUBCOAT
				- (UITools.GAP_LEFT << 1));
		m_task_detail_index = 0;

		m_task_reward = new String[m_task_view.m_detail_size];
		m_task_reward[0] = "奖励经验 : " + m_task_view.m_exp;
		short[] money = ActorRole.getMoney(m_task_view.m_money);
		String moneytext = "奖励金钱 : ";
		if (money[0] > 0) {
			moneytext += (money[0] + "金");
		}
		if (money[1] > 0) {
			moneytext += (money[1] + "银");
		}
		if (money[2] > 0) {
			moneytext += (money[2] + "铜");
		}
		m_task_reward[1] = moneytext;
		int index = 2;
		if (m_task_view.m_propID != null) {
			for (byte i = 0; i < m_task_view.m_propID.length; i++) {
				m_task_reward[index] = "奖励道具 : " + m_task_view.m_propID[i] + " * " + m_task_view.m_propCount[i];
				index++;
			}
		}
		if (m_task_view.m_renownID != null) {
			for (byte i = 0; i < m_task_view.m_renownID.length; i++) {
				m_task_reward[index] = "奖励声望 : " + m_task_view.m_renownID[i] + " * " + m_task_view.m_renownCount[i];
				index++;
			}
		}

//		String[] decipts = UITools.splitString(
//				HyperLink.replaceMark(HyperLink.replaceContent(m_task_view.m_depict)),
//				UITools.WIDTH_SUBCOAT - (UITools.GAP_EACH_LINE << 2));
//		String[] list = new String[m_task_view.m_detail_size - 1 + decipts.length];
//		list[0] = m_task_view.m_name;
//		for (int i = 0; i < decipts.length; i++) {
//			list[1 + i] = decipts[i];
//		}
//		list[decipts.length + 1] = "奖励经验 : " + m_task_view.m_exp;
//		list[decipts.length + 2] = "奖励金钱 : " + m_task_view.m_money;
//		int k = decipts.length + 3;
//		if (m_task_view.m_propID != null) {
//			for (byte i = 0; i < m_task_view.m_propID.length; i++) {
//				list[k] = "奖励道具 : " + m_task_view.m_propID[i];
//				k++;
//				list[k] = "奖励道具数量 : " + m_task_view.m_propCount[i];
//				k++;
//			}
//		}
//		if (m_task_view.m_renownID != null) {
//			for (byte i = 0; i < m_task_view.m_renownID.length; i++) {
//				list[k] = "奖励声望 : " + m_task_view.m_renownID[i];
//				k++;
//				list[k] = "奖励声望数量 : " + m_task_view.m_renownCount[i];
//				k++;
//			}
//		}
//		return list;
	}

	/******************* 网络接收 *********************/

	/**
	 * 读取放弃任务
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvTaskAbort(DataInputStream dis) throws IOException
	{
		short state = dis.readShort();
		String msg = dis.readUTF();
		if (state == 1) {
			Tools.debugPrintln("放弃任务 : " + state + " : " + msg);
			if (!msg.equals("")) {
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C, msg);
			}
			if (m_task_operate_type == TASK_TYPE_DRAMA) {
				GameManager.getInstance().m_role.m_drama_list.removeElementAt(m_task_operate_id);
			}
			else if (m_task_operate_type == TASK_TYPE_EVENT) {
				GameManager.getInstance().m_role.m_event_list.removeElementAt(m_task_operate_id);
			}
			GameManager.getInstance().m_role.stay(GameManager.getInstance().m_role.m_direct);
			GameManager.getInstance().m_role.clearPathfinding();
			setWindowStatus(STATUS_TASK_LIST);
			UIManager.getInstance().removeWindow(m_message_box);
		}
		else {
			Tools.debugPrintln("放弃失败  : " + msg);
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, msg);
		}
	}

	/**
	 * 读取完成任务
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvTaskFinish(DataInputStream dis) throws IOException
	{
		short state = dis.readShort();
		String msg = dis.readUTF();
		if (state == 1) {
			Tools.debugPrintln("完成任务 : " + state + " : msg : " + msg);
			int money = dis.readInt();
			int exp = dis.readInt();
			Tools.debugPrintln("获得金钱 : " + money);
			Tools.debugPrintln("获得经验 : " + exp);
//			UINPCWindow npcWin = GameManager.getInstance().m_npc_window;
//			Task task = (Task)npcWin.m_npc_task.elementAt(npcWin.m_npc_operate_id);
			// 创建一个提示信息
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C, m_task_view.m_name + "完成!");
			Tools.debugPrintln("任务ID : " + m_task_view.m_key);
			if (m_task_view.m_type == TASK_TYPE_DRAMA) {
				ArrayList al = null;
				al = GameManager.getInstance().m_role.m_drama_list;
				for (int i = 0; i < al.size(); i++) {
					Task temp = (Task) al.elementAt(i);
					if (temp.m_key.equals(m_task_view.m_key)) {
						GameManager.getInstance().m_role.m_drama_list.removeElementAt(i);
						break;
					}
				}
			}
			else {
				ArrayList al = null;
				al = GameManager.getInstance().m_role.m_event_list;
				for (int i = 0; i < al.size(); i++) {
					Task temp = (Task) al.elementAt(i);
					if (temp.m_key.equals(m_task_view.m_key)) {
						GameManager.getInstance().m_role.m_event_list.removeElementAt(i);
						break;
					}
				}
			}
			m_task_list_index = 0;
			UIManager.getInstance().removeWindow(this);
			UIManager.getInstance().removeWindow(GameManager.getInstance().m_npc_window.m_win_npc_list);
//			// 删除NPC列表中的任务
//			npcWin.m_npc_task.removeElementAt(npcWin.m_npc_operate_id);
//			npcWin.updateNPCListData();
		}
		else {
			Tools.debugPrintln("完成任务失败  : " + msg);
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, msg);
		}
	}

	/**
	 * 读取接受任务
	 * @param dis
	 * @throws IOException
	 */
	public void recvTaskBegin(DataInputStream dis) throws IOException
	{
		short state = dis.readShort();
		String msg = dis.readUTF();
		if (state == 1) {
			Tools.debugPrintln("接受任务 : " + state + " : " + msg);
			// 得到NPC列表中的任务
//			UINPCWindow npcWin = GameManager.getInstance().m_npc_window;
//			Task task = (Task)npcWin.m_npc_task.elementAt(npcWin.m_npc_operate_id);
			// 创建一个新任务,并将NPC列表中的任务赋给新任务
			Task newTask = new Task();
			newTask.m_name = m_task_view.m_name;
			newTask.m_type = m_task_view.m_type;
			newTask.m_key = m_task_view.m_key;
			// 将新任务放入玩家任务列表
			if (newTask.m_type == TASK_TYPE_DRAMA) {
				GameManager.getInstance().m_role.m_drama_list.addElement(newTask);
			}
			else {
				GameManager.getInstance().m_role.m_event_list.addElement(newTask);
			}
			// 删除NPC列表中的任务
//			npcWin.m_npc_task.removeElementAt(GameManager.getInstance().m_npc_window.m_npc_operate_id);
//			if (npcWin.m_npc_task.size() == 0) {
//				npcWin.m_npc_task = null;
//			}
			//关闭任务窗口类
			UIManager.getInstance().removeWindow(this);
			UIManager.getInstance().removeWindow(GameManager.getInstance().m_npc_window.m_win_npc_list);
//			//刷新NPC列表界面
//			npcWin.updateNPCListData();
			// 创建一个提示信息
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C, "接受任务 : " + newTask.m_name + "!");
		}
		else {
			Tools.debugPrintln("接受任务失败  : " + msg);
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, msg);
		}
	}

	/**
	 * 读取NPC任务详细信息
	 * @param dis
	 * @throws IOException
	 */
	public void recvTaskViewNPC(DataInputStream dis) throws IOException
	{
		short state = dis.readShort();
		String msg = dis.readUTF();
		if (state == 1) {
			m_task_view = new Task();
//			UINPCWindow npcWin = GameManager.getInstance().m_npc_window;
//			Task task = (Task)npcWin.m_npc_task.elementAt(npcWin.m_npc_operate_id);
			m_task_view.m_key = dis.readUTF();
			m_task_view.m_name = dis.readUTF();
			m_task_view.m_type = dis.readByte();
			m_task_view.m_lv = dis.readInt();
			m_task_view.m_difficulty = dis.readByte();
			m_task_view.m_status = dis.readByte();
			m_task_view.m_depict = dis.readUTF();
			m_task_view.m_exp = dis.readInt();
			m_task_view.m_money = dis.readInt();
			Tools.debugPrintln("任务状态: " + m_task_view.m_status);
			Tools.debugPrintln("任务key: " + m_task_view.m_key);
			Tools.debugPrintln("任务名称: " + m_task_view.m_name);
			Tools.debugPrintln("任务类型: " + m_task_view.m_type);
			Tools.debugPrintln("任务等级: " + m_task_view.m_lv);
			Tools.debugPrintln("任务难度等级: " + m_task_view.m_difficulty);
			Tools.debugPrintln("任务描述: " + m_task_view.m_depict);
			Tools.debugPrintln("任务奖励经验数值: " + m_task_view.m_exp);
			Tools.debugPrintln("任务奖励金钱数值: " + m_task_view.m_money);
			m_task_view.m_detail_size = 2;
			byte propListCount = dis.readByte();
			m_task_view.m_detail_size += propListCount;
			Tools.debugPrintln("任务奖励道具列表长度 : " + propListCount);
			m_task_view.m_propID = new String[propListCount];
			m_task_view.m_propCount = new int[propListCount];
			for (byte i = 0; i < propListCount; i++) {
				m_task_view.m_propID[i] = dis.readUTF();
				m_task_view.m_propCount[i] = dis.readInt();
				Tools.debugPrintln("任务奖励道具id" + i + " : " + m_task_view.m_propID[i]);
				Tools.debugPrintln("任务奖励道具数量" + i + " : " + m_task_view.m_propCount[i]);
			}
			byte renownListCount = dis.readByte();
			m_task_view.m_detail_size += renownListCount;
			Tools.debugPrintln("任务奖励声望列表长度 : " + renownListCount);
			m_task_view.m_renownID = new String[renownListCount];
			m_task_view.m_renownCount = new int[renownListCount];
			for (byte i = 0; i < renownListCount; i++) {
				m_task_view.m_renownID[i] = dis.readUTF();
				m_task_view.m_renownCount[i] = dis.readInt();
				Tools.debugPrintln("任务奖励声望目标id: " + i + " : " + m_task_view.m_renownID[i]);
				Tools.debugPrintln("任务奖励声望数值: " + i + " : " + m_task_view.m_renownCount[i]);
			}
			refreshNPCTaskViewData();
//			textBox.setText(getTaskViewData());
			setWindowStatus(STATUS_TASK_NPC_DETAIL);
			if (UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_ID_TASK) == null) {
				UIManager.getInstance().addWindow(this);
			}
		}
		else {
			UIAbstractWindow npcwindow = UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_MENU);
			if (npcwindow != null) {
				UIManager.getInstance().removeWindow(npcwindow);
			}
			Tools.debugPrintln("读取NPC任务详细信息失败 : " + msg);
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, msg);
		}
	}

	/**
	 * 读取玩家任务详细信息
	 * @param dis
	 * @throws IOException
	 */
	public void recvTaskViewRole(DataInputStream dis) throws IOException
	{
		short state = dis.readShort();
		String msg = dis.readUTF();
		if (state == 1) {
			String name = dis.readUTF();
			byte type = dis.readByte();
			Task task = null;
			if (m_task_operate_type == TASK_TYPE_DRAMA) {
				task = (Task) GameManager.getInstance().m_role.m_drama_list.elementAt(m_task_operate_id);
			}
			else if (m_task_operate_type == TASK_TYPE_EVENT) {
				task = (Task) GameManager.getInstance().m_role.m_event_list.elementAt(m_task_operate_id);
			}
			m_task_view = new Task();
			m_task_view.m_status = task.m_status;
			m_task_view.m_key = task.m_key;
			m_task_view.m_name = name;
			m_task_view.m_type = type;
			m_task_view.m_lv = dis.readInt();
			m_task_view.m_difficulty = dis.readByte();
			m_task_view.m_depict = dis.readUTF();
			m_task_view.m_pathfinding_tip = dis.readUTF();
			m_task_view.m_progress = dis.readUTF();
			m_task_view.m_exp = dis.readInt();
			m_task_view.m_money = dis.readInt();
			Tools.debugPrintln("任务名称: " + m_task_view.m_name);
			Tools.debugPrintln("任务类型: " + m_task_view.m_type);
			Tools.debugPrintln("任务等级: " + m_task_view.m_lv);
			Tools.debugPrintln("任务难度等级: " + m_task_view.m_difficulty);
			Tools.debugPrintln("任务描述: " + m_task_view.m_depict);
			Tools.debugPrintln("任务寻路提示: " + m_task_view.m_pathfinding_tip);
			Tools.debugPrintln("任务进度 : " + m_task_view.m_progress);
			Tools.debugPrintln("任务奖励经验数值: " + m_task_view.m_exp);
			Tools.debugPrintln("任务奖励金钱数值: " + m_task_view.m_money);
			m_task_view.m_detail_size = 4;
			byte propListCount = dis.readByte();
			Tools.debugPrintln("任务奖励道具列表长度 : " + propListCount);
			m_task_view.m_propID = new String[propListCount];
			m_task_view.m_propCount = new int[propListCount];
			for (byte i = 0; i < propListCount; i++) {
				m_task_view.m_propID[i] = dis.readUTF();
				m_task_view.m_detail_size++;
				m_task_view.m_propCount[i] = dis.readInt();
				m_task_view.m_detail_size++;
				Tools.debugPrintln("任务奖励道具id: " + i + " : " + m_task_view.m_propID[i]);
				Tools.debugPrintln("任务奖励道具数量: " + i + " : " + m_task_view.m_propCount[i]);
			}
			byte renownListCount = dis.readByte();
			Tools.debugPrintln("任务奖励声望列表长度 : " + renownListCount);
			m_task_view.m_renownID = new String[renownListCount];
			m_task_view.m_renownCount = new int[renownListCount];
			for (byte i = 0; i < renownListCount; i++) {
				m_task_view.m_renownID[i] = dis.readUTF();
				m_task_view.m_detail_size++;
				m_task_view.m_renownCount[i] = dis.readInt();
				m_task_view.m_detail_size++;
				Tools.debugPrintln("任务奖励声望目标id: " + i + " : " + m_task_view.m_renownID[i]);
				Tools.debugPrintln("任务奖励声望数值: " + i + " : " + m_task_view.m_renownCount[i]);
			}

			refreshRoleTaskViewData();
//			textBox.setText(getTaskViewData());
			setWindowStatus(STATUS_TASK_ROLE_DETAIL);
		}
		else {
			Tools.debugPrintln("读取任务详细信息失败 : " + msg);
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, msg);
		}
	}

	/**
	 * 读取玩家任务列表
	 * @param dis
	 * @throws IOException
	 */
	public void recvRoleTaskList(DataInputStream dis) throws IOException
	{
		short state = dis.readShort();
		String msg = dis.readUTF();
		if (state == 1) {
			ActorRole role = GameManager.getInstance().m_role;
			byte dramaCount = dis.readByte();
			Tools.debugPrintln("剧情任务长度 : " + dramaCount);
			role.m_drama_list.removeAllElements();
			for (byte i = 0; i < dramaCount; i++) {
				Task task = new Task();
				task.readTask(dis, TASK_TYPE_DRAMA);
				role.m_drama_list.addElement(task);
				Tools.debugPrintln("创建一个剧情 : " + task.m_name + " : " + task.m_key + " : " + task.m_status);
			}
			byte eventCount = dis.readByte();
			Tools.debugPrintln("活动任务长度 : " + eventCount);
			role.m_event_list.removeAllElements();
			for (byte i = 0; i < eventCount; i++) {
				Task task = new Task();
				task.readTask(dis, TASK_TYPE_EVENT);
				Tools.debugPrintln("创建一个活动 : " + task.m_name + " : " + task.m_key + " : " + task.m_status);
				role.m_event_list.addElement(task);
			}
			byte acceptablyCount = dis.readByte();
			Tools.debugPrintln("可接任务长度 : " + acceptablyCount);
			role.m_acceptably_list.removeAllElements();
			for (byte i = 0; i < acceptablyCount; i++) {
				Task task = new Task();
				task.readTaskByKey(dis, TASK_TYPE_ACCEPTABLY);
				Tools.debugPrintln("创建一个可接 : " + task.m_name + " : " + task.m_key + " : " + task.m_status);
				role.m_acceptably_list.addElement(task);
			}
			m_task_list_status = 0;
			m_task_list_index = 0;
			m_task_list_page = 0;
			UIManager.getInstance().addWindow(GameManager.getInstance().m_task_window);
			setWindowStatus(STATUS_TASK_LIST);
		}
		else {
			Tools.debugPrintln("读取玩家任务列表失败 : " + msg);
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, msg);
		}
	}

//	/**
//	 * 读取更新任务
//	 * @param dis
//	 * @throws IOException
//	 */
//	public void recvTaskUpdate(DataInputStream dis) throws IOException {
//		short state = dis.readShort();
//		String msg = dis.readUTF();
//		if (state == 1) {
//			String key = dis.readUTF();// 更新任务ID
//			byte type = dis.readByte();// 更新任务类型
//			byte status = dis.readByte();// 任务状态
//			String tooltip = dis.readUTF();// 提示
//			String progress = dis.readUTF();// 进度
//			ArrayList al = null;
//			if (type == TASK_TYPE_DRAMA) {
//				al = GameManager.getInstance().m_role.m_drama_list;
//			} else if (type == TASK_TYPE_EVENT) {
//				al = GameManager.getInstance().m_role.m_event_list;
//			}
//			for (int i = 0; i < al.size(); i++) {
//				Task task = (Task) al.elementAt(i);
//				if (task.m_key.equals(key)) {
//					task.m_status = status;
//					task.m_tooltip = tooltip;
//					task.m_progress = progress;
//					Tools.debugPrintln("更新状态 : " + status);
//					Tools.debugPrintln("更新提示 : " + tooltip);
//					Tools.debugPrintln("更新进度 : " + progress);
//					break;
//				}
//			}
//			Tools.debugPrintln("更新ID" + key + "任务成功!状态为 : " + status);
//		} else {
//			Tools.debugPrintln("更新任务失败 : " + msg);
//		}
//	}
	/**
	 * 任务寻路提示
	 * @param dis
	 * @throws IOException
	 */
	public void recvTaskHintPathfinding(DataInputStream dis) throws IOException
	{
		m_pathfinding_hint = dis.readUTF();
		Tools.debugPrintln("任务寻路提示 : " + m_pathfinding_hint);
		m_hyperLinker = null;
		if (AbsHyperLinker.isHyperLink(m_pathfinding_hint)) {
			m_hyperLinker = AbsHyperLinker.createHyperLinker(m_pathfinding_hint, UITools.W_COVER_SUBCOAT
					- UITools.H_SUBCOAT_SIDE, UITools.H_COVER_SUBCOAT);
			if (m_hyperLinker.getHyperLinkSize() != 0) {
				for (int i = 0; i < m_hyperLinker.getHyperLinkTypes().length; i++) {
					if (m_hyperLinker.getHyperLinkTypes()[i] == AbsHyperLinker.URL_NPC) {
						m_pathfinding_index = 0;
						setWindowStatus(STATUS_TASK_HINT_PATHFINDING);
						UIManager.getInstance().removeOtherWindows();
						UIManager.getInstance().addWindow(GameManager.getInstance().m_task_window);
						GameManager.getInstance().m_role.stay(GameManager.getInstance().m_role.m_direct);

//					UISkill skill = (UISkill)UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_SKILL);
//					Tools.debugPrintln("关闭skill : " + skill);
//					if (skill != null) {
//						UIManager.getInstance().removeWindow(skill);
//					}
//					UIBag bag = (UIBag)UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_BAG);
//					Tools.debugPrintln("关闭bag : " + bag);
//					if (bag != null) {
//						UIManager.getInstance().removeWindow(bag);
//					}
//					UIMenu menu = (UIMenu)UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_MENU_LR);
//					Tools.debugPrintln("关闭menu : " + menu);
//					if (menu != null) {
//						UIManager.getInstance().removeWindow(menu);
//					}
//					UINpcShop shop = (UINpcShop)UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_NPCSHOP);
//					Tools.debugPrintln("关闭shop : " + shop);
//					if (shop != null) {
//						UIManager.getInstance().removeWindow(shop);
//					}
//					
//					UIDialogMenu dialog = (UIDialogMenu)UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_MENU);
//					Tools.debugPrintln("关闭dialogmenu : " + dialog);
//					if (dialog != null) {
//						UIManager.getInstance().removeWindow(dialog);
//					}
						return;
					}
				}
			}
		}
		UIManager.getInstance().removeWindow(this);
	}

	/**
	 * 更新玩家身上任务状态
	 * @param dis
	 * @throws IOException
	 */
	public void recvTaskUpdateStatus(DataInputStream dis) throws IOException
	{
		String key = dis.readUTF();
		byte type = dis.readByte();
		byte status = dis.readByte();
		Tools.debugPrintln("更新任务状态 : " + key + " : " + type + " : " + status);
		ArrayList list = null;
		if (type == 0) {
			list = GameManager.getInstance().m_role.m_drama_list;
		}
		else if (type == 1) {
			list = GameManager.getInstance().m_role.m_event_list;
		}
		if (list != null) {
			Task task;
			for (int i = 0; i < list.size(); i++) {
				task = (Task) list.elementAt(i);
				if (task.m_key.equals(key)) {
					task.m_status = status;
					break;
				}
			}
		}
	}

	/******************* 坐标,宽高 *********************/
	// ////////////////个人任务列表信息/////////////////////
	// 状态标题栏
//	private int LIST_COORD_X_TITLE = 0;// 需要根据图片算高度
//	private int LIST_COORD_Y_TITLE = 0;// 需要根据图片算高度

	// ////////////////任务详细信息/////////////////////

	/******************* 状态 *********************/
	public final int STATUS_TASK_NONE = 0;//没有界面
	public static final int STATUS_TASK_LIST = 1;// 个人任务列表
	public final int STATUS_TASK_ROLE_DETAIL = 2;// 任务详细信息
	public final int STATUS_TASK_NPC_DETAIL = 3;//NPC任务详细信息
	public final int STATUS_TASK_HINT_PATHFINDING = 4;//任务寻路提示界面
	public final int STATUS_TASK_TEACH = 5;//新手教学
//	private int m_status = STATUS_TASK_LIST;

	public static final byte TASK_TYPE_DRAMA = 0;// 剧情
	public static final byte TASK_TYPE_EVENT = 1;// 活动
	public static final byte TASK_TYPE_ACCEPTABLY = 2;//可接

	/** 任务状态 - 未接 */
	public static final byte TASK_STATUS_NORECEIVE = 0;// 未接
	/** 任务状态 - 未完成 */
	public static final byte TASK_STATUS_NOFINISH = 1;// 未完成
	/** 任务状态 - 完成 */
	public static final byte TASK_STATUS_FINISH = 2;// 完成

	private int m_task_list_status = 0;// 任务列表状态
//	private final int TASK_TYPE_DRAMA = 0;//剧情
//	private final int TASK_TYPE_EVENT = 1;//活动
//	private final int TASK_TYPE_ACCEPTABLY = 2;//可接

	private byte m_task_list_index = 0;// 任务列表索引
	private byte m_task_list_page = 0;// 任务列表页数
	private int m_task_detail_index = 0;//任务详细信息索引
//	private int m_task_detail_page = 0;//任务详细信息页数
	public Task m_task_view = null;//任务详细信息
	public static UIMessageBox m_message_box = null;//放弃任务提示
	public int m_task_operate_id = 0;//正在操作的下标/id
	private int m_task_operate_type = 0;//正在操作的任务类型 剧情/活动
	/******************* 图片 *********************/
//	private Image img_title_small = null;// 窗口标题栏
//	private Image img_title_middle = null;// 窗口标题中间块
//	private Image img_select_corner = null;// 选择按钮的角
	private Image img_word_store = null;// 剧情
	private Image img_word_action = null;// 活动
	private Image img_word_active = null;// 可接
//	private Image img_scroll_bar_arrows = null;// 滚动条箭头
//	private Image img_scroll_bar_ruling = null;// 滚动条中间刻度
//	private Image img_border_corner = null;// 外框角

//	private Image img_softkey = null;// 左右软键按钮
	/******************* 自身常量 *********************/
	private String[] m_task_reward = null;//NPC任务奖励列表
	private String[] m_task_view_list = null;//NPC任务详细信息
	private String m_task_title = null;//任务名字
	private AbsHyperLinker m_hyperLinker = null;
//	private AbsHyperLinker m_task_role_view = null;//玩家任务详细信息
	private String[] m_role_view_array = null;
	private byte m_task_role_view_index = 0;//玩家详细信息翻页下标
	private boolean m_task_give_up = false;//是否选择了放弃任务
	private boolean m_task_view_page = false;//是否在任务详细信息翻页上
//	private String m_no_hyperLinker = null;//去掉超链接的字符串
	private final String WORD_PATHFINDING = "点击寻路!";
	private String m_pathfinding_hint = null;//寻路提示字符串
	private int m_pathfinding_index = 0;//寻路提示下标
//	private final int BUTTON_BIG_YES = 0;// 按钮被按下
//	private final int BUTTON_BIG_NO = 1;// 按钮没有被按下
//	private final int BUTTON_BIG_COUNT = 2;// 按钮总数
////////////////////
	private int[][] mlabel = null;
	protected void registerTouch() {
		clearAllRects();
		registerNormalSoft();
		
		switch(m_state) {
		case STATUS_TASK_LIST:
			mlabel = new int[][]{
					{165,38,49,19},
					{215,38,49,19},
					{265,38,49,19},
					//
					{447,52,19,34},//up
					{447,236,19,34},//down
			};
			initTouchRect(mlabel);
			int[][] listRect = new int[UITools.AMOUNT_SUBCOAT_HT_CONTENT][];
			for (int i = 0; i < UITools.AMOUNT_SUBCOAT_HT_CONTENT; i++) {
				listRect[i] = new int[] { UITools.X_SUBCOAT_HT,
						UITools.Y_SUBCOAT_HT + i * UITools.H_SINGLE_BAR,
						UITools.W_SUBCOAT_HT, UITools.H_SINGLE_BAR };
			}
			initTouchRect(listRect);
			break;
		case STATUS_TASK_HINT_PATHFINDING:
//			default:
			initTouchRect(new int[][]{
					{UITools.X_BG_SMALL + (UITools.W_BG_SMALL >> 1) - 34,
						UITools.Y_BG_SMALL + UITools.H_BG_SMALL - 4 - 16, 68, 16},
			});
			break;
		case STATUS_TASK_ROLE_DETAIL:
			initTouchRect(new int[][] {
					{UITools.X_BG + (UITools.W_BG >> 1) -34,
						UITools.Y_BG + UITools.H_BG - 3 - 16, 68, 16},	
			});
			break;
		}
	}

	protected void onTouchRect(int[][] rect, int touchid) {
		switch(m_state) {
			case STATUS_TASK_LIST:
			if(rect == mlabel) {
				switch(touchid) {
				case 0:
				case 1:
				case 2:
					m_task_list_page = 0;
					m_task_list_index = 0;
					m_task_list_status = touchid;
					break;
				case 3:
					GameTouchManager.keyPressedDir(1);
					break;
				case 4:
					GameTouchManager.keyPressedDir(3);
					break;
				}
			} else {
				int len = 0;
				switch (m_task_list_status) {
					case TASK_TYPE_DRAMA:
						len = GameManager.getInstance().m_role.m_drama_list.size();
						break;
					case TASK_TYPE_EVENT:
						len = GameManager.getInstance().m_role.m_event_list.size();
						break;
					case TASK_TYPE_ACCEPTABLY:
						len = GameManager.getInstance().m_role.m_acceptably_list.size();
						break;
				}
				if (touchid < len) {
					GameTouchManager.keyPressedFire();
				}
			}
			break;
			default:
//			case STATUS_TASK_HINT_PATHFINDING:
				GameTouchManager.keyPressedFire();
				break;
		}
	}

	protected void actionOnStateChanged() {
		registerTouch();
	}
	
	
	
	
}
